#!/opt/midware/python3/bin/python3
# -*- coding: utf-8 -*-
# @Time    : 2024/12/24 13:03
# @File    : s.py
# @Software: PyCharm

import asyncio
import websockets

loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)

async def echo(websocket):
    print(websocket)
    # print(path)
    async for message in websocket:
        print(f"Received message: {message}")
        await websocket.send(f"Echo: {message}")


async def run_server():
    print(asyncio.get_running_loop())
    async with websockets.serve(echo, '127.0.0.1', 9090):
        # await websocket.send("1")
        await asyncio.Future()


if __name__ == '__main__':

    # start_server = websockets.serve(echo, "127.0.0.1", 9090)
    #
    # loop.run_until_complete(start_server)
    # loop.run_forever()
    asyncio.run(run_server())


    # loop.run_until_complete(run_server())